package com.a0soft.gphone.aTruffleHog.di;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */

import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.Context;

import com.a0soft.gphone.aTruffleHog.util.MiscUtil;

class MemInfo extends BaseInfo {    
	//private static final String LOG_TAG = MemInfo.class.getSimpleName();
	
	static void
    Build(DeviceInfo di)
    {
		final String[] strFields = new String[] {
			"MemTotal:", "SwapTotal:"};
		final long[] lSizes = new long[strFields.length];
		MiscUtil.ReadProcLines("/proc/meminfo", strFields, lSizes);
		di.Put(DeviceInfoKey.K.MI_RAM_TOTAL, lSizes[0] * 1024);
		di.Put(DeviceInfoKey.K.MI_SWAP_TOTAL, lSizes[1] * 1024);
		
		Context ctx = MiscUtil.GetAppContext();
		ActivityManager am = (ActivityManager)ctx.getSystemService(Context.ACTIVITY_SERVICE);
		MemoryInfo mi = new MemoryInfo();
		am.getMemoryInfo(mi);
		di.Put(DeviceInfoKey.K.MI_THRESHOLD, mi.threshold);
		
		Runtime runtime = Runtime.getRuntime();
		di.Put(DeviceInfoKey.K.MI_VM_MAX_MEM, runtime.maxMemory());
		
        di.Put(DeviceInfoKey.K.MI_NATIVE_HEAP, android.os.Debug.getNativeHeapSize());
    }	
}
